package com.fmatos.amazingwallpapers.image.database.orm.repository;


import java.sql.SQLException;
import java.util.List;

import javax.inject.Inject;

import android.util.Log;

import com.fmatos.amazingwallpapers.image.database.orm.Album;
import com.fmatos.amazingwallpapers.image.database.orm.DatabaseHelper;
import com.j256.ormlite.dao.Dao;

public class AlbumRepo {

	private static final String TAG = AlbumRepo.class.getSimpleName();
	
	private Dao<Album, String> albumDao;
	
	
	@Inject
	public AlbumRepo(DatabaseHelper databaseHelper) {
		albumDao = databaseHelper.getAlbumDao();
	}

	public List<Album> getAlbums() throws SQLException {
		return albumDao.queryForAll();
	}

	public Album getAlbum(String name) throws SQLException {
		return albumDao.queryForId(name);
	}

	public void createAlbum(Album album) throws SQLException {
		Log.i(TAG,"create album " + album.getName());
		Album newAlbum = albumDao.createIfNotExists(album);
		Log.i(TAG,"new album " + newAlbum.getName());
	}

	public void updateAlbum(Album album) throws SQLException {
		albumDao.update(album);
		
	}

}
